package com.example.devsa_platform.pojo.doc;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.csv.CSVRecord;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;

import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@Document(indexName = "professional_developer",createIndex = false)
public class ProfessionalDeveloperDoc {
    @Field(name = "t_branch")
    private String TBranch;
    @Field(name = "i_cor_pm")
    private String ICorPM;
    @Field(name = "work_exp")
    private String WorkExp;
    @Field(name = "knowledge_1")
    private String Knowledge1;
    @Field(name = "knowledge_2")
    private String Knowledge2;
    @Field(name = "knowledge_3")
    private String Knowledge3;
    @Field(name = "knowledge_4")
    private String Knowledge4;
    @Field(name = "knowledge_5")
    private String Knowledge5;
    @Field(name = "knowledge_6")
    private String Knowledge6;
    @Field(name = "knowledge_7")
    private String Knowledge7;
    @Field(name = "knowledge_8")
    private String Knowledge8;
    @Field(name = "frequency_1")
    private String Frequency1;
    @Field(name = "frequency_2")
    private String Frequency2;
    @Field(name = "frequency_3")
    private String Frequency3;
    @Field(name = "time_searching")
    private String TimeSearching;
    @Field(name ="time_answering")
    private String TimeAnswering;
    @Field(name = "professional_tech")
    private String ProfessionalTech;
    @Field(name = "industry")
    private String Industry;
    @Field(name = "survey_length")
    private String SurveyLength;
    @Field(name = "survey_ease")
    private String SurveyEase;

    public ProfessionalDeveloperDoc(CSVRecord record) {
        this.TBranch = getValueOrDefault(record.get("TBranch"));
        this.ICorPM = getValueOrDefault(record.get("ICorPM"));
        this.WorkExp = getValueOrDefault(record.get("WorkExp"));
        this.Knowledge1 = getValueOrDefault(record.get("Knowledge_1"));
        this.Knowledge2 = getValueOrDefault(record.get("Knowledge_2"));
        this.Knowledge3 = getValueOrDefault(record.get("Knowledge_3"));
        this.Knowledge4 = getValueOrDefault(record.get("Knowledge_4"));
        this.Knowledge5 = getValueOrDefault(record.get("Knowledge_5"));
        this.Knowledge6 = getValueOrDefault(record.get("Knowledge_6"));
        this.Knowledge7 = getValueOrDefault(record.get("Knowledge_7"));
        this.Knowledge8 = getValueOrDefault(record.get("Knowledge_8"));
        this.Frequency1 = getValueOrDefault(record.get("Frequency_1"));
        this.Frequency2 = getValueOrDefault(record.get("Frequency_2"));
        this.Frequency3 = getValueOrDefault(record.get("Frequency_3"));
        this.TimeSearching = getValueOrDefault(record.get("TimeSearching"));
        this.TimeAnswering = getValueOrDefault(record.get("TimeAnswering"));
        this.ProfessionalTech = getValueOrDefault(record.get("ProfessionalTech"));
        this.Industry = getValueOrDefault(record.get("Industry"));
        this.SurveyLength = getValueOrDefault(record.get("SurveyLength"));
        this.SurveyEase = getValueOrDefault(record.get("SurveyEase"));
}
    private String getValueOrDefault(String value) {
        return Objects.equals(value, "NA") ? "No Answer" : value;
    }

}
